package Practice;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Ps4 {
    public static void main(String[] args) {
        distributeCandies(70,4);
    }
    public static int[] distributeCandies(int candies, int num_people) {
        int[] ans = new int[num_people];
        int cycleCandies = (1+num_people)*num_people / 2;
        int cycle = cycleCandies;
        int countCycle = 0;
        while(candies - cycle >= 0){
            candies-=cycle;
            countCycle++;
            cycle = cycle+num_people*num_people;
        }
        if(countCycle > 0){
            for(int i = 0 ; i < num_people ; i++){
                ans[i] = countCycle*(countCycle-1)/2*num_people+countCycle*(i+1);
            }
        }
        // 当前剩余糖果不足给所有小朋友都分一次，那么从第一个小朋友开始模拟
        int cur = 0;
        int curCandies = countCycle * num_people + 1;
        while(candies - curCandies >= 0){
            ans[cur] = ans[cur] + curCandies;
            cur++;
            candies -= curCandies;
            curCandies++;
        }
        ans[cur] = ans[cur] + candies;
        return ans;
    }
}
